//
//  MJTEmoticonButton.swift
//  swiftWeiBo
//
//  Created by MJT on 16/7/20.
//  Copyright © 2016年 MJT. All rights reserved.
//

import UIKit

class MJTEmoticonButton: UIButton {

    //保存表情模型
    var emoticon: MJTEmoticon? {
        didSet {
            guard let etn = emoticon else {
                return
            }
            //显示
            self.hidden = false
            if etn.type == "0" {
                // 如果是图片,则不用设置title
                self.setImage(UIImage(named: etn.path!), forState: .Normal)
                self.setTitle(nil, forState: .Normal)
            } else {
                //emoji 如果是emoji,则不用设置image
                self.setImage(nil, forState: .Normal)
                self.setTitle((etn.code! as NSString).emoji(), forState: .Normal)
            }
        }
    }

}
